package com.mic.yzzn.plc.web.controller.unitTest;

import com.mic.yzzn.plc.model.ContactPoint;
import com.mic.yzzn.plc.model.ContactSection;
import com.mic.yzzn.plc.model.PLCReadRequest;
import com.mic.yzzn.plc.model.Station;
import com.mic.yzzn.plc.web.controller.PLCController;
import com.sun.org.apache.regexp.internal.recompile;
import com.mic.yzzn.plc.common.control.datastructure.*;

import java.rmi.RMISecurityManager;
import java.util.ArrayList;

/**
 * Created by ASH on 16/5/3.
 */
public class BufferReadTest
{
    public static void main(String[] args) {
        System.setSecurityManager(new RMISecurityManager() {
            public void checkConnect (String host, int port) {}
            public void checkConnect (String host, int port, Object context) {}
        });

        Station station = new Station();
        station.setCode("tty.usbserial-A403QGGT-01");
        PLCController controller = new PLCController();

        PLCReadRequest readRequest = new PLCReadRequest();
        readRequest.setStation(station);
        readRequest.setRequestType(PLCMission.PLCMissionTypeReadNormal);

        ArrayList<ContactPoint> contactPoints = new ArrayList<>();
        ContactPoint p2 = new ContactPoint("D21000");
        ContactPoint p3 = new ContactPoint("R1102");
        ContactPoint p4 = new ContactPoint("R1103");
        ContactPoint p5 = new ContactPoint("R1004");
        ContactPoint p6 = new ContactPoint("R1005");
        ContactPoint p7 = new ContactPoint("R1006");
        ContactPoint p8 = new ContactPoint("R200F");
        ContactPoint p9 = new ContactPoint("D20001");
        ContactPoint p10 = new ContactPoint("D9000"); // 非法点位

        contactPoints.add(p2);
        contactPoints.add(p3);
        contactPoints.add(p4);
        contactPoints.add(p5);
//        contactPoints.add(p6);
//        contactPoints.add(p7);
//        contactPoints.add(p8);
//        contactPoints.add(p9);
//        contactPoints.add(p10);

        readRequest.setPointList(contactPoints);

//        ArrayList<ContactSection> contactSections = new ArrayList<>();
//
//        contactSections.add(new ContactSection("R2000", "R2002"));
//        contactSections.add(new ContactSection("D20000", "D19999")); // 非法连续地址
//        readRequest.setSectionList(contactSections);

        System.out.println(controller.bufferRead(readRequest).getBody());
    }
}
